package com.example.sellersale.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.sellersale.entity.Goods;
import com.example.sellersale.entity.GoodsType;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Repository
public interface GoodsMapper extends BaseMapper<Goods> {

    @Select("select * from sys_goods")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "goodsName",property = "goodsName"),
            @Result(column = "goodsNum",property = "goodsNum"),
            @Result(column = "goodsType",property = "goodsType"),
            @Result(column = "inPrice",property = "inPrice"),
            @Result(column = "outPrice",property = "outPrice"),
            @Result(column = "goodsType",property = "description",javaType= GoodsType.class,
                one=@One(select = "com.example.sellersale.mapper.GoodsTypeMapper.selectById")
            )
    })
   List<Goods> selectList();

    /**
     * 等用户购买商品的时候，该商品的库存应该少相应的数量
     * @param num
     * @param id
     * @return
     */
    @Update("update sys_goods set goodsNum =#{num} where id=#{id}")
    int updateNum(Integer num,String id);

    @Select("select * from sys_goods where goodsName=#{name}")
    Goods selectGoodsByName(String name);

}
